<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\NoteService;

class BatchCreateNoteConsumer extends BaseConsumer
{

    // 要消费的队列名
    public $queue = 'batch_create_note';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * 任务排期
     * @param $data
     * @throws \Throwable
     * @throws \think\Exception
     */
    public function doConsume($data)
    {
        try {

            $noteService = NoteService::getInstance();
            foreach ($data as $dataItem) {
                request()->getUserId($dataItem['created_by']);
                $noteService->createNote($dataItem);
            }

        } catch (\Throwable $e) {
            trace(format_exception_info($e), 'ERR');
        }
    }
}
